/************************************************************
* @file   gkt_keypad.h
************************************************************/

#ifndef GKT_KEYPAD_H
#define GKT_KEYPAD_H

#include "gkt_types.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "gkt_keypad_defines.h"

enum {
	GKT_KEY_ACTION_RELEASE = 0,
	GKT_KEY_ACTION_SHORT_PRESS,
	GKT_KEY_ACTION_LONG_PRESS,
	GKT_KEY_ACTION_MAX
};

/* keypad keyinfo
 * MPT: multi-point touch
 */
typedef struct _gkt_keypad_keyinfo {
	uint32_t	action;
	uint32_t	repeat_count;
	uint32_t	channel;	/* key channel */
} gkt_keypad_keyinfo_s;

/* control */
typedef enum {
	GKT_KEYPAD_CTRL_DISABLE = 0,
	GKT_KEYPAD_CTRL_ENABLE,
	GKT_KEYPAD_CTRL_REAL_TRIM,
	GKT_KEYPAD_CTRL_MAX
} gkt_keypad_ctrl_e;

enum { 
	GKT_KEYPAD_REAL_TRIM_DISABLE = 0, 
	GKT_KEYPAD_REAL_TRIM_ENABLE, 
	GKT_KEYPAD_REAL_TRIM_BACKUP, 
	GKT_KEYPAD_REAL_TRIM_RESTORE, 
	GKT_KEYPAD_REAL_TRIM_MAX
};

/*calibrate status*/
typedef enum {
	GKT_KEYPAD_CALIBRATE_ACTIVE = 0,
	GKT_KEYPAD_CALIBRATE_STANDBY,
	GKT_KEYPAD_CALIBRATE_CARD,
	GKT_KEYPAD_CALIBRATE_MAX
}gkt_keypad_calibrate_status_e;

enum {
	GKT_KEYPAD_RESPONSE_STANDARD = 2,
	GKT_KEYPAD_RESPONSE_SENSITIVITY,
	GKT_KEYPAD_RESPONSE_MAX
};

enum {
	GKT_KEYPAD_PAPAMETERS_STANDARD = 0,
	GKT_KEYPAD_PAPAMETERS_SENSITIVE,
	GKT_KEYPAD_PAPAMETERS_MAX
};

enum {
	GKT_KEYPAD_PRINT_CLOSE = 0,
	GKT_KEYPAD_PRINT_OPEN,
	GKT_KEYPAD_PRINT_MAX
};

#define GKT_CONFIG_KEYPAD_ADVANCE_TIMER_DEVID		1

#ifdef GKT_CONFIG_KEYPAD_PAPAMETERS
#define GKT_KEYPAD_PAPAMETERS_L2(mode_name)	\
		GKT_KEYPAD_PAPAMETERS_##mode_name
#define GKT_KEYPAD_PAPAMETERS_L1(mode_name)	\
		GKT_KEYPAD_PAPAMETERS_L2(mode_name)
#define GKT_KEYPAD_PAPAMETERS	\
		GKT_KEYPAD_PAPAMETERS_L1(GKT_CONFIG_KEYPAD_PAPAMETERS)
#else
#define GKT_KEYPAD_PAPAMETERS	GKT_KEYPAD_PAPAMETERS_STANDARD
#endif

/* keypad notify function */
typedef void (*gkt_keypad_notify_fn)(gkt_keypad_keyinfo_s *keyinfo);

/************************************************************
 *  |----|----------|--------|--------|--------|------
 *  t0   t1         t2       t3       t4       t5
 *
 *  debounce_time   = t1 - t0
 *  long_press_time = t2 - t0
 *  repeat_interval = t3 - t2 = t4 - t3 = t5 - t4 = ...
 *  
 *  key was pressed down at t0
 *  1. if key is released before t1
 *     >> no valid event is notified;
 *  2. if key is released after t1 and before t2
 *     >> a normal/short press event is notified;
 *     >> action = GKT_KEY_ACTION_SHORT_PRESS
 *     >> repeat_count is ingored;
 *  3. if key is released after t2 and before t3
 *     >> the 1st long press event is notified;
 *     >> action = GKT_KEY_ACTION_LONG_PRESS
 *     >> repeat_count = 0;
 *  4. if key is released after t3 and before t4
 *     >> the 2nd long press event is notified
 *     >> action = GKT_KEY_ACTION_LONG_PRESS
 *     >> repeat_count = 1;
 *  and so on ...
 *
 *  some keypads may support release action feature, when a key
 *  is released, an event 
 *     >> action = GKT_KEY_ACTION_RELEASE,
 *     >> repeat_count is ignored
 *  is notified
 ************************************************************/
 
typedef struct _gkt_keypad_config_params {
	uint32_t	debounce_time;	/* unit in ms */
	uint32_t	long_press_time;	/* unit in ms */
	uint32_t	repeat_interval;	/* unit in ms */
	gkt_keypad_notify_fn	notify;
} gkt_keypad_config_params_s;

int gkt_keypad_init(void);

int gkt_keypad_config(gkt_keypad_config_params_s *params);

int gkt_keypad_control(gkt_keypad_ctrl_e control, uint32_t ext_data);

uint32_t gkt_keypad_self_inspect(void);

int gkt_keypad_get_channel_freqs(uint32_t freqs[GKT_CONFIG_KEYPAD_CHANNEL_NUMS]);

int gkt_keypad_get_channel_delta(uint32_t freqs[GKT_CONFIG_KEYPAD_CHANNEL_NUMS], 
						int channel_delta[GKT_CONFIG_KEYPAD_CHANNEL_NUMS], uint32_t eliminate_dc);

int gkt_keypad_get_channel_base_freqs(uint32_t *channel_freqs);

uint32_t gkt_keypad_get_wakeup_channel(void);

void gkt_keypad_window_resume(void);

int gkt_keypad_calibrate(uint32_t force, uint32_t status);

int gkt_keypad_update_backup_freq(void);

int gkt_keypad_parameter_update(uint32_t response);

void gkt_keypad_parameter_print_open(void);

void gkt_keypad_real_trim_print_open(void);

void gkt_keypad_peak_control(gkt_keypad_ctrl_e control); 

void gkt_keypad_update_base_freqs(void);

#if defined(GKT_CONFIG_KEY_DOUBLE_LOCK_CHANNEL)
int gkt_keypad_anti_lock_standby(void);

int gkt_keypad_anti_lock_release(void);
#endif
#if defined(GKT_CONFIG_KEYPAD_SPT5115S_ENABLE)	\
	&& GKT_CONFIG_KEYPAD_SPT5115S_ENABLE
int gkt_keypad_spt5115s_test_mode_control(gkt_keypad_ctrl_e control);
#endif

#ifdef __cplusplus
}
#endif

#endif	/* GKT_KEYPAD_H */

